package org.fastiot.gateway

import grails.testing.gorm.DomainUnitTest
import org.fastiot.protocol.Packet
import spock.lang.Specification

class MessageSpec extends Specification implements DomainUnitTest<org.fastiot.gateway.Message> {

    def setup() {
    }

    def cleanup() {
    }

    void "Test a valid properties"() {
        given:
        def instance = new org.fastiot.gateway.Message(
                dateReceived: dateReceived, direction: direction, metadata: metadata, contents: contents
        )

        when:
        instance.save(flush: true)

        then:
        !instance.hasErrors()

        where:
        dateReceived << [new Date()]
        direction << [Packet.Direction.Upstream]
        metadata << [
                [
                        Oid            : "LN1234567890123456", Pid: 0x0940, DateSent: "2018-02-14 12:13:14",
                        "RemoteAddress": "10.11.12.13:23462", SN: 1234, DateReceived: "2018-02-14 12:13:14"
                ]
        ]
        contents << [
                "7e0940001438393836303131353831333030373230333332351802182334183c02140139364942014901460f5cdc29009c48ea490301a17e".bytes //fake
        ]
    }
}
